package com.pig4cloud.pig.demo.Controller;

import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.demo.Service.CommentService;
import com.pig4cloud.pig.demo.feign.Entity.Comment;
import com.pig4cloud.pig.demo.feign.Entity.CommentAndLikeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Inner
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/comment/getCommentAndLike/{id}/{currentUserId}/{currentPage}/{pageSize}")
    public R getCommentAndLike(
            @PathVariable Long id,
            @PathVariable Long currentUserId,
            @PathVariable int currentPage,
            @PathVariable int pageSize) {
        List<CommentAndLikeVO> lists = commentService.getCommentAndLike(id, currentUserId, currentPage, pageSize);
        if (lists.size() == 0)
            return R.failed();
        return R.ok(lists);
    }

//    @GetMapping("/comment/getCommentTotal/{id}")
//    public R getCommentTotal(@PathVariable Long id) {
//        int total = commentService.getCommentTotal(id);
//        if (total == 0)
//            return R.failed();
//        return R.ok(total);
//    }
}
